{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7ded1d57",
   "metadata": {},
   "source": [
    "# 切片练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1e5e3c71",
   "metadata": {},
   "outputs": [],
   "source": [
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)   #list() 可以将 str  to （转）  list\n",
    "print(phrase)\n",
    "print(plist)\n",
    "\n",
    "on_str = ''.join(plist[1:3])\n",
    "print(on_str)\n",
    "new_phrase = on_str+ ''.join(plist[5]+plist[4]+plist[7]+plist[6])\n",
    "print(plist)\n",
    "print(new_phrase)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "edcdf51b",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "e6f2c1cf",
   "metadata": {},
   "source": [
    "# 列表的高级用法（课堂练习）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cd8ba4b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_成绩 = [97,95,93,95,92,96,92,95,100]\n",
    "\n",
    "# 3.2 pop() 删除 pop()不填内容  对应记忆 ==> append() 删除末位\n",
    "# 目标： 使用pop()删除 成绩为95 的所有值\n",
    "# for i in stu_成绩\n",
    "#     if i == 95:\n",
    "#         print(stu_成绩.index(i))\n",
    "\n",
    "# 本质： list 本身有 index & value\n",
    "pop_index_list = []\n",
    "for index,value in enumerate(stu_成绩):\n",
    "    # print(index,value)\n",
    "    if value == 95:\n",
    "        # stu_成绩.pop(index)\n",
    "        stu_成绩[index] += 1\n",
    "        # print(index,value)\n",
    "print(stu_成绩)\n",
    "\n",
    "stu_id = [10001,10002,10003,10004,10008,10001,10009,10010,10001]\n",
    "# 思考，如何取出所有位置10001的index？\n",
    "for i in stu_id:\n",
    "    # 循环遍历stu_id的所有内容\n",
    "    if i == 10001:\n",
    "        # 判断如果元素为10001的时候,怎么取出索引值呢？\n",
    "        print()\n",
    "## 一般方法?\n",
    "\n",
    "# 枚举:因为list其实不仅有values值，还有index索引，但for循环主要循环遍历其值，不遍历索引\n",
    "# 因此，有了枚举的方法，同时遍历两者\n",
    "# enumerate()\n",
    "pop_values_list = []  # append方法经常用于新建列表\n",
    "for index,item in enumerate(stu_id):\n",
    "    # print(index,item)\n",
    "    if item == 10001:\n",
    "        print(index,item)\n",
    "        pop_values_list.append(index)\n",
    "print(\"我们想要删除pop()的值：\",pop_values_list)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
